<template>
  <div id='app' style='height:100%;width:100%;'>
    <canvas id='bcCanvas' style='position:fixed;left:0;top:0;z-index:0;'></canvas>
    <router-view></router-view>
  </div>
</template>

<script>
import { Request } from '@/utils'
import star from '@/utils/effect/star.js'
export default {
  name: 'app',
  methods : {
    refreshLogin () {
      var loginExpire = this.$store.getters.loginExpire()
      var offsetTime = Math.floor((loginExpire - new Date() * 1) / 1000)
      if(this.$store.state.loginStatus && offsetTime <= 50) { //还有100s就登录过期了
        console.log('刷新登录')
        var req = new Request()
        req.get('common/refresh/token', res => {
          if(res.success && res.data) {
            var data = res.data
            this.$store.commit('setLoginToken', data.access_token) //设置登录token
            this.$store.commit('setLoginExpire', 3600 + 600) //设置登录状态时效
            this.$store.commit('setRefreshToken', data.refresh_token) //设置刷新token
          }
        }, {refreshToken : this.$store.state.refreshToken})
      }
      
    }
  },

  mounted () {
      star()

      this.refreshLogin()
			setInterval(() => {
				this.refreshLogin()
			}, 100000)
  }
}
</script>
